package com.dq.domain.service;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liuhui
 * @date 2019/11/20 0020 12:52:22
 */
@Data
@Entity
@ApiModel("服务项目")
public class ServiceProject extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("服务项目编号")
    protected String projectNo;

    @ApiModelProperty("服务项目名称")
    @NotBlank
    protected String projectName;

    @ApiModelProperty("服务项目价格")
    @NotNull
    protected BigDecimal projectPrice;
    @ApiModelProperty("提成比例")
    protected BigDecimal projectProportion;

    @ApiModelProperty("服务项目描述")
    @Column(columnDefinition = "text")
    protected String projectDescription;

    @ApiModelProperty("服务所属分类id")
    @Transient
    protected List<Long> serviceCategoryIds = new ArrayList<>();
    @ApiModelProperty("服务所属分类id")
    @Transient
    protected List<String> serviceCategoryNames = new ArrayList<>();
    @ApiModelProperty("服务手工费")
    protected BigDecimal projectManualPrice;
    @ApiModelProperty("服务需要时间")
    protected Long serviceTime;
    @ApiModelProperty("图片")
    protected String imgUrl;

    @Data
    @ApiModel(value = "服务项目视图")
    public static class Vo implements VO {
        @ApiModelProperty("服务项目id")
        protected Long id;
        @ApiModelProperty("服务项目编号")
        protected String projectNo;
        @ApiModelProperty("服务项目名称")
        protected String projectName;
        @ApiModelProperty("服务项目价格")
        protected BigDecimal projectPrice;
        @ApiModelProperty("提成比例")
        protected BigDecimal projectProportion;
        @ApiModelProperty("服务项目描述")
        protected String projectDescription;
        @ApiModelProperty("服务手工费")
        protected BigDecimal projectManualPrice;
        @ApiModelProperty("服务需要时间")
        protected Long serviceTime;
        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;

        @ApiModelProperty("服务所属分类id")
        protected List<Long> serviceCategoryIds = new ArrayList<>();
        @ApiModelProperty("服务所属分类id")
        protected List<String> serviceCategoryNames = new ArrayList<>();
        @ApiModelProperty("图片")
        protected String imgUrl;
    }

    @Data
    @ApiModel("门店服务记录多个服务")
    public static class OrgServiceProjectList{
        protected Long id;
        protected String name;
    }

    public OrgServiceProjectList toOrgServiceProjectList(){
        ServiceProject.OrgServiceProjectList orgServiceProjectList = new ServiceProject.OrgServiceProjectList();
        orgServiceProjectList.id = this.getId();
        orgServiceProjectList.name = fmt(this.getProjectName());
        return orgServiceProjectList;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.projectNo = this.projectNo;
        vo.projectName = this.projectName;
        vo.projectPrice = this.projectPrice;
        vo.projectProportion = this.projectProportion;
        vo.projectDescription = this.projectDescription;
        vo.projectManualPrice = this.projectManualPrice;
        vo.serviceTime = this.serviceTime;
        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();

        vo.serviceCategoryIds = this.getServiceCategoryIds();
        vo.serviceCategoryNames = this.getServiceCategoryNames();
        vo.imgUrl = this.getImgUrl();
        return vo;
    }

}
